//
//  ShouYinDingDanViewController.m
//  EJLX
//
//  Created by adc on 15/11/15.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "ShouYinDingDanViewController.h"
#import "ShouYinDingDanTableViewCell.h"

#import "HomeVC.h"
#import "HttpsManager.h"
#import "woDeDingDan.h"
#import "twoWoDeDingDan.h"
#import "GMDCircleLoader.h"
@interface ShouYinDingDanViewController ()

@end

@implementation ShouYinDingDanViewController
-(void)viewWillAppear:(BOOL)animated
{
    NSString*str=@"0";
    
    [HttpsManager requestGetWodeDingDan:str Competion:^(woDeDingDan *dingDan) {
        
        if (dingDan==nil)
        {
            LoginVC*vc=[[LoginVC alloc]init];
            vc.hidesBottomBarWhenPushed=YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else
        {
            _dingDan=dingDan;
            
            _dataAry=dingDan.listAry;
            __weak ShouYinDingDanViewController *weakSelf = self;
            [tabel1 addPullToRefreshWithActionHandler:^{
                NSLog(@"当进行下拉刷新执行该方法");
                [weakSelf performSelector:@selector(requestEnd) withObject:nil afterDelay:1.0f];
            }];
            
            [tabel1 addInfiniteScrollingWithActionHandler:^{
                [weakSelf performSelector:@selector(requestEnd) withObject:nil afterDelay:1.0f];
            }];

            [tabel1 reloadData];
        }
       
        
        
        
        
    }];

}
- (void)requestEnd{
    [tabel1.pullToRefreshView stopAnimating];
    
    [tabel1.infiniteScrollingView stopAnimating];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    // Do any additional setup after loading the view from its nib.

    [GMDCircleLoader setOnView:self.view withTitle:@"请稍等..." animated:YES];
    self.navigationController.navigationBarHidden=YES;
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 20, WIDE, 44)];
    view.backgroundColor=RGB_COLOR(0x00c49f);
    [self.view addSubview:view];
    UIButton*backBut=[[UIButton alloc]initWithFrame:CGRectMake(10,7,30,30)];
    [backBut setBackgroundImage:[UIImage imageNamed:@"返回箭头"] forState:UIControlStateNormal];
    [backBut addTarget:self action:@selector(backBut) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:backBut];
    UILabel*daoLabel=[[UILabel alloc]initWithFrame:CGRectMake(WIDE/2-40, 7,80, 30)];
    daoLabel.text=@"我的订单";
    daoLabel.textAlignment=NSTextAlignmentCenter;
    daoLabel.textColor=[UIColor whiteColor];
    [view addSubview:daoLabel];

    for (int i=0;i<2; i++)
    {
        UIButton*bigBut=[[UIButton alloc]initWithFrame:CGRectMake(0+WIDE/2*i, 64, WIDE/2,50)];
        bigBut.tag=i+1;
        NSArray*ary=[NSArray arrayWithObjects:@"已完成",@"付款失败", nil];
        [bigBut setTitle:ary[i] forState:UIControlStateNormal];
        bigBut.font=[UIFont systemFontOfSize:12];
        [bigBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [bigBut setTitleColor:RGB_COLOR(0x00c49f) forState:UIControlStateSelected];
        if (i==0)
        {
            bigBut.selected=YES;
            _select=bigBut.tag;
            _a=0;
        }
        [bigBut addTarget:self action:@selector(bigButClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:bigBut];
    }

    
    
    tabel1=[[UITableView  alloc]initWithFrame:CGRectMake(0,64+40+10, WIDE, 230) style:UITableViewStylePlain];
    tabel1.delegate=self;
    tabel1.dataSource=self;
    [self.view addSubview:tabel1];

   tabel1.separatorStyle=NO;
       label=[[UILabel alloc]initWithFrame:CGRectMake(0,64+40,WIDE/2,2)];
    label.backgroundColor=RGB_COLOR(0x00c49f);
    [self.view addSubview:label];
       [tabel1 registerNib:[UINib nibWithNibName:@"ShouYinDingDanTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
      [GMDCircleLoader hideFromView:self.view animated:YES];
}

-(void)bigButClick:(UIButton*)sender
{
    UIButton*lastBut=(UIButton*)[self.view viewWithTag:_select];
    lastBut.selected=NO;
    
    sender.selected=YES;
    _select=sender.tag;
    _a=sender.tag-1;
    NSLog(@"----%d",_select);
    [UIView animateWithDuration:1 animations:^{
        label.frame=CGRectMake(WIDE/2*(sender.tag-1), 64+40,WIDE/2,2);
    } completion:^(BOOL finished) {
        nil;
    }];
        NSInteger index=sender.tag-1;
    
    
        NSString*str=[NSString stringWithFormat:@"%ld",(long)index];
        [HttpsManager requestGetWodeDingDan:str Competion:^(woDeDingDan *dingDan) {
    
            if (dingDan==nil)
            {
                LoginVC*vc=[[LoginVC alloc]init];
                vc.hidesBottomBarWhenPushed=YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            else
            {
                _dingDan=dingDan;
                
                _dataAry=dingDan.listAry;
                
                [tabel1 reloadData];
            }

            
            
    
    
        }];
    
        
        


}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _dataAry.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
   


    twoWoDeDingDan*two=_dataAry[indexPath.row];
    ShouYinDingDanTableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
    [cell.otherBut setTitle:@"付款" forState:UIControlStateNormal];
    [cell.otherBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cell.otherBut addTarget:self action:@selector(daiFuKuan) forControlEvents:UIControlEventTouchUpInside];
    [cell.otherBut setBackgroundColor:RGB_COLOR(0X00C49f)];
    cell.time.text=two.tradeDate;
    cell.name.text=two.channel;
    //NSString*money=[NSString stringWithFormat:@"%d",two.money];
    cell.money.text=[NSString stringWithFormat:@"%.2f",two.money*0.01];
    return cell;
    
}
//返回按钮
-(void)backBut
{
    self.tabBarController.tabBar.hidden=YES;
    self.hidesBottomBarWhenPushed=YES;
    HomeVC*vc=[[HomeVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
  
    
}
-(void)daiFuKuan
{
    
}
-(void)shiBaiBut
{
    
}
-(void)guanBiBut
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
